﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace Inovout.Web.Mvc
{
    public static class LinkExtensions
    {
        //public static MvcHtmlString RootLink(this HtmlHelper htmlHelper, string linkText, string controller = null, object id = null, IDictionary<string, object> htmlAttributes = null)
        //{

        //    string url = htmlHelper.RouteLink(linkText, new { controler = controller, id = id }).ToHtmlString();
        //    if (string.IsNullOrEmpty(controller))
        //    {
        //        url = UrlHelper.GenerateContentUrl("~/", htmlHelper.ViewContext.HttpContext);
        //    }
        //    else
        //    {
        //        url = UrlHelper.GenerateContentUrl("~/" + controller, htmlHelper.ViewContext.HttpContext);
        //    }
        //    TagBuilder tagBuilder = new TagBuilder("a")
        //    {
        //        InnerHtml = (!String.IsNullOrEmpty(linkText)) ? HttpUtility.HtmlEncode(linkText) : String.Empty
        //    };
        //    tagBuilder.MergeAttributes(htmlAttributes);
        //    tagBuilder.MergeAttribute("href", url);
        //    return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal));
        //}

        public static MvcHtmlString BreadCrumb(this HtmlHelper htmlHelper, Navigation breadCrumb, string separator = "-")
        {
            StringBuilder htmlStringBuilder = new StringBuilder();
            htmlStringBuilder.AppendFormat("<a href=\"{0}\">{1}</a>", breadCrumb.Url, breadCrumb.Text);
            foreach (var item in breadCrumb.Items)
            {
                htmlStringBuilder.AppendFormat(" {0} <a href=\"{1}\">{2}</a>",separator, item.Url, item.Text);
            }
            return MvcHtmlString.Create(htmlStringBuilder.ToString());
        }
    }
}
